#lang r5rs
;(define (square-tree-1 tree)
;  (cond (((null? (car tree))  
(define (tree-map f tree)
  (cond ((null? tree) '())
         ((not (pair? (car tree))) (append (list (f (car tree))) (tree-map f (cdr tree))))
         ((pair? (car tree)) (append (list (tree-map f (car tree))) (tree-map f (cdr tree))))))

(define (square-tree tree)
  (tree-map (lambda (x) (* x x)) tree))



(define (subsetsss s)
  (define (transform set)
    (map (lambda (x) (list x)) set))
  (define (union from to)
    (append to (list from) (map (lambda (x) (append from x)) to)))
  (define (subset origin to)
    (if(null? origin)
       to
       (subset (cdr origin) (union (car origin) to))))
  (subset (transform s) '()))
;(define (subsets s)
;  (if (null? s)
;      (list '())
;      (let ((rest (subsets (cdr s))))
;        (append rest (map <> rest)))))

                                         

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(display (square-tree
 (list 1
       (list 2 (list 3 4) 5)
       (list 6 7))))
(newline)
(display (append (list '()) (subsetsss (list 1 2 3 4 5)) ))